#include "titlebar.h"
#include "ui_titlebar.h"

Titlebar::Titlebar(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Titlebar),
    isMaximized(false)
{
    ui->setupUi(this);

    connect(ui->btnMin, &QPushButton::clicked, this, [=](){
        parentWidget()->showMinimized();
    });

    connect(ui->btnMax, &QPushButton::clicked, this, [=](){
        parentWidget()->showMaximized();if (isMaximized) {
            // 如果窗口已经最大化，恢复到原来大小
            parentWidget()->showNormal();
            isMaximized = false;
        } else {
            // 如果窗口未最大化，将其最大化
            parentWidget()->showMaximized();
            isMaximized = true;
        }
    });

    connect(ui->btnClose, &QPushButton::clicked, this, [=](){
        parentWidget()->close();
    });

}

Titlebar::~Titlebar()
{
    delete ui;
}
